package model

import (
	"gitee.com/carollia/data-sdk-go/utils"
	"errors"
)

// 用户行为事件
type Action struct {
	Type       string                 `json:"type"`
	Time       int64                  `json:"time"`
	Event      string                 `json:"event"`
	Uid        string                 `json:"uid"`
	UidType    string                 	  `json:"uid_type"`
	Properties map[string]interface{} `json:"properties"`
}

func (action *Action) Normalize() error {
	action.Type = "action"
	action.Time = utils.GetCNTimeNow()
	// check uid
	if action.Uid == "" || len(action.Uid) == 0 {
		return errors.New("property [uid] can't be empty")
	}
	if len(action.Uid) > 255 {
		return errors.New("the max length of property [uid] is 255")
	}
	// check model
	if action.Event == "" {
		return errors.New("model name can't be empty")
	}
	if action.Properties == nil {
		action.Properties = map[string]interface{}{}
	}
	return nil
}
